package com.hlyx.gamebox;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.bumptech.glide.Glide;

import java.util.ArrayList;

public class GameGridAdapter extends ArrayAdapter<GameItemModel> {
    Context mContext;
    public GameGridAdapter(@NonNull Context context, ArrayList<GameItemModel> gameItemModels){
        super(context, 0 , gameItemModels);
        mContext = context;
    }

    @NonNull
    @Override
    public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
        View listItemView = convertView;
        if (listItemView == null) {
            // Layout Inflater inflates each item to be displayed in GridView.
            listItemView = LayoutInflater.from(getContext()).inflate(R.layout.game_item, parent, false);
        }
        GameItemModel gameItemModel = getItem(position);
        ImageView ivIcon = listItemView.findViewById(R.id.game_icon);
        String url = gameItemModel.getThumb();
        Glide.with(mContext)
                .load(url)
                .centerCrop()
                .placeholder(R.drawable.ic_launcher_background)
                .timeout(30000)
                .into(ivIcon);

        return listItemView;
    }
}
